package org.business.accounting.beans;

import org.business.accounting.interfaces.RegistrationHelper;
import org.business.accounting.interfaces.User;
import org.business.accounting.service.UserDAO;

public class RegistrationHelperBean implements RegistrationHelper {

	private UserDAO userDAO;
	private User tmpUser;
	
	public RegistrationHelperBean(UserDAO userDAO) {
		this.userDAO = userDAO;
		this.tmpUser = new UserBean();
	}
	
	public boolean register() {
		User user = userDAO.get(tmpUser.getUserName());
		boolean isRegistered = user != null;
		
		if (!isRegistered) {
			userDAO.save(tmpUser);
			return true;
		}
		
		return false;
	}

	public UserDAO getUserDAO() {
		return userDAO;
	}

	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
	}

	public User getTmpUser() {
		return tmpUser;
	}

	public void setTmpUser(User tmpUser) {
		this.tmpUser = tmpUser;
	}

}
